﻿-- =============================================
-- Script Template
-- =============================================
USE [DB_Ex]
GO

/****** Object:  StoredProcedure [dbo].[sp_Axapta_TradeSale_LastMonth]    Script Date: 12/05/2011 10:43:04 ******/
SET ANSI_NULLS ON
GO

SET QUOTED_IDENTIFIER ON
GO

-- =============================================
-- Author:		<Author,,Name>
-- Create date: <Create Date,,>
-- Description:	<Description,,>
-- =============================================
CREATE PROCEDURE [dbo].[sp_Axapta_TradeSale_LastMonth] 
AS
BEGIN

-- SET NOCOUNT ON added to prevent extra result sets from
-- interfering with SELECT statements.
SET NOCOUNT ON;

Declare @dt as datetime;
SELECT @dt = DATEADD(month, -0, SYSDATETIME());
Declare @dtFrom as date;
Declare @dtFrom2 as datetime;
SELECT @dt = DATEADD(day, (DAY(@dt)*-1+1), @dt);
select @dtFrom = CAST(@dt as date);
select @dtFrom2 = CAST(@dtFrom as datetime);

SELECT [TRANSDATE]
      ,[INVENTLOCATIONID]
      ,[NAME]
      ,[Total]
FROM [DB_Ex].[dbo].[vw_Axapta_TradeSale]
WHERE (TRANSDATE >= @dtFrom2) 
ORDER BY TRANSDATE DESC, NAME


END

GO


